package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.entity.User;
import cn.kgc.ssm.mapper.UserMapper;
import cn.kgc.ssm.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/7/24
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> userList() {

       List<User> users =  userMapper.selectAll();
        return users;
    }

    @Override
    public Map<String,Object> userPage(Integer page, Integer limit) {

        PageHelper.startPage(page,limit);
        List<User> users = userMapper.selectAll();

        PageInfo<User> userPageInfo = new PageInfo<>(users);
        long total = userPageInfo.getTotal();

        HashMap<String, Object> result = new HashMap<>();
        result.put("total",total);
        result.put("pageData",users);

        return result;
    }
}
